//
// Created by jsjxsy on 2022/8/22.
//
#include <fstream>
#include <iostream>
using namespace std;
static const int buffer_length = 2048;
bool copyFile(const string &src, const string &dest) {
  ifstream fin;
  fin.open(src, ios_base::in | ios_base::binary);
  if (fin.fail()) {
    cerr << "file src:" << src << " open fail" << endl;
    perror("file error:");
    return false;
  }

  ofstream fout;
  fout.open(dest, ios_base::binary | ios_base::trunc);
  if (fout.fail()) {
    cerr << "file dest:" << dest << " open fail" << endl;
    fin.close();
    perror("file error:");
    return false;
  }
  char temp[buffer_length];
  while (!fin.eof()) {
    fin.read(temp, buffer_length);
    streamsize size = fin.gcount();
    fout.write(temp, size);
  }


  fin.close();
  fout.close();
  return true;
}
int main() {
  bool result = copyFile("../data/Blue Daube.mp3", "../data_copy/Blue Daube2.mp3");
  if (result) {
    cout << "copy file success" << endl;
  } else {
    cout << "copy file fail" << endl;
  }
  return 0;
}